package gtkwire.widget;

import gtkwire.*;
import gtkwire.listener.EntryListener;
import gtkwire.listener.connector.EntryListenerFilter;

/**
*A single line text entry field.
*/
public class GtkEntry extends GtkWidget
{
	public GtkEntry()
	{
		super();
		this.widgetType = WT_GtkEntry;
		gtkCreate();
	}

	public GtkEntry( String name, GladeKey key )
	{
		super( name, key );
		this.widgetType = WT_GtkEntry;

	}
	/**
	*Sets the text in the widget to the given value, replacing the current contents.
	*/
	public void setText( String text )
	{
		app().sendCommand( name, GTKWireCommand.SET_TEXT, text );
	}

	/**
	*Retrieves the contents of the entry widget.
	*/
	public String getText()
	{
		GTKWireMessage answer = app().sendCommandRequest( name, widgetType, GTKWireCommandRequest.GET_TEXT, null );
		return (String) answer.getMessageObject();
	}

	/**
	*Changes the size request of the entry to be about the right size for n_chars characters. 
	*Note that it changes the size request, the size can still be affected by how you pack the widget into containers. 
	*If n_chars is -1, the size reverts to the default entry size.
	*/
	public void setWidthInChars( int width )
	{
		app().sendCommand( name, GTKWireCommand.SET_WIDTH, width );
	}

	/**
	*Sets the maximum allowed length of the contents of the widget.
	*If the current contents are longer than the given length, then they will be truncated to fit.
	*/
	public void setMaxLength( int max )
	{
		app().sendCommand( name, GTKWireCommand.SET_MAX, max );
	}

	/**
	*Adds listener that is notified always when entry is changed.
	*/
	public void addEntryListener( EntryListener listener )
	{
		EntryListenerFilter el = new EntryListenerFilter( listener );
		el.addFilteringName( name );
		app().addListener( el );
	}

}//end class